# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lua-mediator
_pkgname=mediator_lua
pkgver=1.1.2
_pkgver=$pkgver-0
pkgrel=2
pkgdesc="Mediator pattern implementation for pub-sub management"
url="http://olivinelabs.com/mediator_lua/"
arch="noarch"
license="MIT"
source="$_pkgname-$pkgver.tar.gz::https://github.com/Olivine-Labs/$_pkgname/archive/v$_pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$_pkgver"
# This module needs lua-busted to run tests, but lua-busted depends on
# lua-mediator and we wanna avoid circular dependencies.
options="!check"

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$_pkgname/$_pkgver"

	cd "$builddir"
	install -m 644 -D src/mediator.lua \
		"$subpkgdir"/usr/share/lua/$lver/mediator.lua

	mkdir -p "$rockdir"
	echo 'rock_manifest = {}' > "$rockdir"/rock_manifest
}

sha512sums="116d08a96fa0bd540ac4d3cac61a529a634cba3621c6f2e917b405462bbc0e2ab5b170dc6819e470105cdedf958a382945819eaff4affa63bc057824c163c8a0  mediator_lua-1.1.2.tar.gz"
